import React, { useState } from 'react';

function AddContactForm({ onAdd }) {
    const [name, setName] = useState('');
    const [phone, setPhone] = useState('');
    const [address, setAddress] = useState('');

    const handleSubmit = (e) => {
        e.preventDefault();
        onAdd({ name, phone, address });
        setName('');
        setPhone('');
        setAddress('');
    };

    return (
        <form onSubmit={handleSubmit}>
            <div>
                <label>姓名:</label>
                <input type="text" value={name} onChange={(e) => setName(e.target.value)} required />
            </div>
            <div>
                <label>电话号码:</label>
                <input type="text" value={phone} onChange={(e) => setPhone(e.target.value)} required />
            </div>
            <div>
                <label>地址:</label>
                <input type="text" value={address} onChange={(e) => setAddress(e.target.value)} required />
            </div>
            <button type="submit">添加联系人</button>
        </form>
    );
}

export default AddContactForm;
